package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.PersonInfo;
import com.budwk.app.sqfw.services.PersonInfoService;
import com.budwk.app.sqfwV2.dto.dto.PersonInfoDTO;
import com.budwk.app.sqfwV2.dto.vo.PersonHouseVo;
import com.budwk.app.sqfwV2.dto.vo.PersonInfoReqVo;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;

@IocBean
@At("/platform/sqfwV2/personInfo")
@ApiDefinition(tag = "人员信息api")
@Slf4j
public class PersonInfoController {

    @Inject
    private PersonInfoService personInfoService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "人员信息列表")
    @ApiFormParams(implementation = PersonInfoReqVo.class)
    @SaCheckLogin
    public Result<Pagination> listPersonByPage(@Param("..") PersonInfoReqVo reqVo) {
        log.info("personInfo listPersonByPage param: {}", JSONObject.toJSONString(reqVo));
        return personInfoService.listPersonByPage(reqVo);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "人员信息采集记录")
    @ApiFormParams(implementation = PersonInfoReqVo.class)
    @SaCheckLogin
    public Result<Pagination> listPersonRecordByPage(@Param("..") PersonInfoReqVo reqVo) {
        log.info("personInfo listPersonRecordByPage param: {}", JSONObject.toJSONString(reqVo));
        return personInfoService.listPersonRecordByPage(reqVo);
    }

    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除人员信息")
    @SLog(tag = "删除人员信息", value = "${args[0]}")
    @ApiFormParams(implementation = PersonInfoReqVo.class)
    @SaCheckLogin
    public Result<?> deleteData(@Param("..") PersonInfoReqVo reqVo) {
        log.info("personInfo deleteData param: {}", JSONObject.toJSONString(reqVo));
        personInfoService.deleteData(reqVo);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询人员详情信息")
    @SaCheckLogin
    public Result<?> getPersonDetail(@Param("personId") String personId, @Param("type") String type) {
        return Result.data(personInfoService.getPersonDetail(personId, type));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询人员最新填报记录信息")
    @SaCheckLogin
    public Result<?> queryPersonDetail(@Param("personId") String personId) {
        return Result.data(personInfoService.queryPersonDetail(personId));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "新增|编辑|走访采集人员")
    @SLog(tag = "新增|编辑|走访采集人员", value = "${args[0]}")
    @ApiFormParams(implementation = PersonInfoDTO.class)
    @SaCheckLogin
    public Result<PersonInfo> submitData(@Param("..") PersonInfoDTO reqVo) {
        log.info("personInfo submitData param: {}", JSONObject.toJSONString(reqVo));
        return Result.data(personInfoService.submitData(reqVo));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "新增|编辑人员")
    @SLog(tag = "新增|编辑人员", value = "${args[0]}")
    @ApiFormParams(implementation = PersonInfoDTO.class)
    @SaCheckLogin
    public Result<PersonInfo> saveOrUpdatePerson(@Param("..") PersonInfoDTO reqVo) {
        log.info("personInfo submitData param: {}", JSONObject.toJSONString(reqVo));
        return Result.data(personInfoService.saveOrUpdatePerson(reqVo));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询人员已经关联的房屋信息")
    @ApiFormParams(implementation = PersonInfoDTO.class)
    @SaCheckLogin
    public Result<List<PersonHouseVo>> queryRelateHouse(@Param("personId") String personId) {
        return Result.data(personInfoService.queryRelateHouse(personId));
    }
}
